<?
session_start();
require_once "utils.php";
$state = "";
if (isset($_GET["todo"])) {
    switch ($_GET["todo"]) {
        case "login":
            if (isset($_POST["login"]) && isset($_POST["pwd"])) {
                if (Utilisateur::verifyUser($_POST["login"],$_POST["pwd"])) {
                    $_SESSION["login"] = $_POST["login"];
                     $state = "login";
                    } else {
                        $state = "wrong";
                    }
            } else {$state = "empty";}
            break;
        case "logout":
            session_unset();
            session_destroy();
            $state="logout";
            break;
        default:
            break;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <div><? echo isset($_SESSION["login"])?$_SESSION["login"]:"No user"?></div>
        <?php
        if (isset($_SESSION["login"])) {
            echo ($state=="login"?"Log in suessed! ":"")."welcome! ".$_SESSION["login"]." <a href=\"index.php?todo=logout\">Logout</a>";
        } else {
            switch ($state) {
                case "wrong":
                    echo "username or password incorrect!";
                    break;
                case "logout":
                    echo "logout suessed!";
                    break;
                case "empty":
                    echo "please fill all fields!";
                    break;
                default:
                    break;
            }
            require_once 'printLoginForm.php';
        }
        ?>

        <div id="test">`J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha}`</div>
        <script type="text/javascript" src="http://www1.chapman.edu/~jipsen/mathml/ASCIIMathML.js"></script>
        <script type="text/javascript">
            //AMprocessNode(document.getElementById("test"));
        </script>
    </body>
</html>
